package operation;

import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书!");
        System.out.print("请输入想要借阅的图书:");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int curSize=bookList.getUsedSize();
        if(curSize==0) {
            System.out.println("没有图书可以借阅");
            return;
        }
        for (int i=0; i < curSize; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                if(bookList.getBook(i).isBorrowed()) {
                    System.out.println("该图书已被借阅!");
                    return;
                }
                bookList.getBook(i).setBorrowed(true);
                System.out.println("成功借阅图书!");
                return;
            }
        }
        System.out.println("没有该图书可以借阅");

    }
}



